package erwiki.ui.app.handlers;

import java.util.List;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.swt.widgets.Shell;

import erwiki.api.auth.ISessionMonitor;
import erwiki.api.core.Engine;
import erwiki.api.core.WikiSession;
import erwiki.api.rwc.RWC;
import erwiki.ui.app.parts.WikiPageViewer;
import jakarta.inject.Inject;
import jakarta.inject.Named;

public class PageEditHandler {

	@Inject
	Engine engine;

	@Execute
	public void execute(MApplication application, EModelService service, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
		WikiSession session = RWC.INSTANCE.getWikiSession();
		System.out.println("Edit Page");

		List<MPart> parts = service.findElements(application, "erwiki.ui.part.wikiPageViewer",
                MPart.class, null);
		MPart part = parts.get(0);
		WikiPageViewer wikiPageViewer = (WikiPageViewer) part.getObject() ;
		wikiPageViewer.startEditPage();
	}
}
